﻿@model PessModel.Archive

@{
    ViewBag.Title = "Edit Proposal";
    PessModel.PAuthor pauthor = new PessModel.PAuthor() { ArchiveID = Model.ID };
    ViewBag.AllowEdit = true;
    ViewBag.ArchiveID = Model.ID;
    ViewBag.Format = Model.CountyCode;

    if (Model.PAuthors.Count() == 0)
    {
        pauthor = new PessModel.PAuthor()
        {
            ArchiveID = Model.ID,
            Country = Model.Country,
            EMail = Model.EMail,
            FirstName = Model.FirstName,
            LastName = Model.LastName,
            Order = 1,
            Organization = Model.SchoolName,
        };
    }

    ViewBag.DefaultAuthor = pauthor;
}

<h2>Edit Proposal</h2>
<div id="operate">
    
</div>
@using (Html.BeginForm("EditProposal", "Author", FormMethod.Post))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset class="edit">
        <legend></legend>
        <div class="heading" style="margin-top:-15px;">
            Proposal Information
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.ProjectTitle)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.ProjectTitle,new { style="width:600px;"}) *
            @Html.ValidationMessageFor(model => model.ProjectTitle)
        </div>
        <div class="editor-label">
            Track:
        </div>
        <div class ="editor-field">
            @Html.DropDownList("Tracks", "Please select a track") (Select a track first to get topics.)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model=>model.SubjectID)
        </div>
        <div class="editor-field">
            @*<select id="SubjectID" name="SubjectID">
                <option value="">Please select a topic</option>
            </select> *@
            @Html.DropDownList("SubjectID", string.Empty)*
            @Html.ValidationMessageFor(model => model.SubjectID)
            
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.CountyCode)
        </div>
        <div class="editor-field">
            @Html.DropDownList("CountyCode") *
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.SchoolComment)
        </div>
        <div class="editor-field" style="height:130px">
            @Html.TextAreaFor(model => model.SchoolComment, new { style = "width:600px;height:110px" })
            <div>* Words count: <span id="SchoolCommentcount"></span>/100. @Html.ValidationMessageFor(model => model.SchoolComment)</div>
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.CountyEBComment)
        </div>
        <div class="editor-field" style="height:250px">
            @Html.TextAreaFor(model => model.CountyEBComment, new { style = "width:600px;height:230px" })
            <div>* Words count: <span id="CountyEBCommentcount"></span>/1000. @Html.ValidationMessageFor(model => model.CountyEBComment)</div>
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.PrimaryKeyword)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.PrimaryKeyword,new { style="width:400px;"}) *
            @Html.ValidationMessageFor(model => model.PrimaryKeyword)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.SecondaryKeyword)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.SecondaryKeyword,new { style="width:400px;"})
            @Html.ValidationMessageFor(model => model.SecondaryKeyword)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.TechnologyRequirements)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.TechnologyRequirements,new { style="width:400px;"})
            @Html.ValidationMessageFor(model => model.TechnologyRequirements)
        </div>
        <div class="heading">
            Contact Information
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.EMail)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.EMail) *
            @Html.ValidationMessageFor(model => model.EMail)
        </div>
        <div class="inline">
            <div class="editor-label">
                @Html.LabelFor(model => model.FirstName)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.FirstName) *
                @Html.ValidationMessageFor(model => model.FirstName)
            </div>
        
            <div class="editor-label">
                @Html.LabelFor(model => model.LastName)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.LastName) *
                @Html.ValidationMessageFor(model => model.LastName)
            </div>
        </div>

        <div class="inline">
            <div class="editor-label">
                @Html.LabelFor(model => model.PhoneNumber)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.PhoneNumber) *
                @Html.ValidationMessageFor(model => model.PhoneNumber)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.FAX)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.FAX)
                @Html.ValidationMessageFor(model => model.FAX)
            </div>
        </div>
        <div class="inline">
            <div class="editor-label">
                @Html.LabelFor(model => model.SchoolName)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.SchoolName) *
                @Html.ValidationMessageFor(model => model.SchoolName)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.ProfessionalTitle)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.ProfessionalTitle)
                @Html.ValidationMessageFor(model => model.ProfessionalTitle)
            </div>
        </div>
        <div class="inline">
            <div class="editor-label">
                @Html.LabelFor(model => model.Address1)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Address1) *
                @Html.ValidationMessageFor(model => model.Address1)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.Address2)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Address2)
                @Html.ValidationMessageFor(model => model.Address2)
            </div>
        </div>

        <div class="inline">
            <div class="editor-label">
                @Html.LabelFor(model => model.City)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.City) *
                @Html.ValidationMessageFor(model => model.City)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.StateProvince)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.StateProvince) *
                @Html.ValidationMessageFor(model => model.StateProvince)
            </div>
        </div>

        <div class="inline">
            <div class="editor-label">
                @Html.LabelFor(model => model.ZipCode)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.ZipCode) *
                @Html.ValidationMessageFor(model => model.ZipCode)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.Country)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Country) *
                @Html.ValidationMessageFor(model => model.Country)
            </div>
        </div>
        <div class="heading" >
            Authors
        </div>
        <div style="width:700px">@Html.Partial("_CreatePAuthor", Model.PAuthors)</div>
            

        @Html.HiddenFor(model => model.UserID)
        @Html.HiddenFor(model => model.Status)
        @Html.HiddenFor(model => model.Gender)
        @Html.HiddenFor(model => model.GradeLevel)
        <div class="heading" style="margin-top:15px;height:1px;padding:0px;">

        </div>
        <div class="editor-btn">
            <input type="submit" value="Save" />
            @Html.ActionLink("Cancel", "Proposals")    
        </div>
    </fieldset>
}  
   
    

<script type="text/javascript">
    $(document).ready(function () {
        $("#Tracks").change(function (event) {
            //alert($("#Tracks").val());
            $.ajax({
                url: "@Url.Action("GetTopics", "Subject")",
                type: 'POST',
                data: { trackID: $("#Tracks").val() },
                success: function (topics) {
                    $('#SubjectID').empty();
                    //$("#SubjectID").append("<option value='0'>--Select Topic--</option>");
                    $.each(topics, function (i, topic) {
                        //alert(topics[i]);
                        $('<option>', { value: topic.TopicID }).html(topic.Name).appendTo($('#SubjectID'));
                    });
                }
            });
        });

        $("#SchoolComment").keyup(function (event) {//check change event
            Trancuate(this.id, 100);
        });

        $("#CountyEBComment").keyup(function (event) {
            Trancuate(this.id, 1000);
        });

        $("#SchoolComment").change(function (event) {//check change event
            Trancuate(this.id, 100);
        });

        $("#CountyEBComment").change(function (event) {
            Trancuate(this.id, 1000);
        });

    });

    function Trancuate(id, wordscount)
    {
        //replace multiple spaces with one space
        id = "#" + id;
        var count = $(id).val().trim().split(' ',wordscount).length;
        $(id+"count").html(count);
        //if (count == wordscount)
        //    $(id).val($(id).val().trim());
        if (count >= wordscount) {
            //the better way is to find the index of the count+1 space
            $(id).val($(id).val().trim().split(' ', wordscount).join(' '));
        }
    }

    

    $(function()
    {
        $("#SchoolCommentcount").html($("#SchoolComment").val().trim().split(' ').length);
        $("#CountyEBCommentcount").html($("#CountyEBComment").val().trim().split(' ').length);
    })
</script>